package com.ddwl.gate.dao;

import com.ddwl.common.constant.Constant;
import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.gate.mapper.MobileRechargeConfigMapper;
import com.ddwl.gate.model.MobileRechargeConfig;
import com.ddwl.schema.bo.gate.MobileRechargeConfigPageBo;
import com.ddwl.schema.vo.gate.MobileRechargeConfigVo;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author hemiaojun
 * @Date 2020/9/23 17:42
 */
@Repository
public class MobileRechargeConfigDao extends TkDao<MobileRechargeConfigMapper, MobileRechargeConfig> {

    @Resource
    private MobileRechargeConfigMapper mobileRechargeConfigMapper;

    public List<MobileRechargeConfig> getList(MobileRechargeConfigPageBo bo) {
        Example example = getExample();
        example.and().andEqualTo("operator", bo.getOperator())
                .andEqualTo("enable",bo.getEnable())
                .andEqualTo("itemId",bo.getItemId());
        return mobileRechargeConfigMapper.selectByExample(example);
    }

    public MobileRechargeConfig getByCondition(MobileRechargeConfig entity) {
        return selectOne(entity);
    }

    public List<MobileRechargeConfigVo> queryByOperator(byte operator) {
        MobileRechargeConfig entity=new MobileRechargeConfig();
        entity.setOperator(operator);
        List<MobileRechargeConfig> list= select(entity);
        list=list.stream().sorted(Comparator.comparing(MobileRechargeConfig::getFacePrice)).collect(Collectors.toList());
        return BeanConverUtils.convertBeanList(list, MobileRechargeConfigVo.class);
    }

    public List<MobileRechargeConfig> getByFacePriceExcludeItemId(MobileRechargeConfig entity) {
        Example example = getExample();
        example.and().andEqualTo("facePrice", entity.getFacePrice())
                .andNotEqualTo("itemId",entity.getItemId());
        return mobileRechargeConfigMapper.selectByExample(example);
    }

    public List<MobileRechargeConfig> getAll() {
        Example example = new Example(MobileRechargeConfig.class);
        return mobileRechargeConfigMapper.selectByExample(example);
    }

    public void changeId(Map<String, String> map) {
        mobileRechargeConfigMapper.changeId(map);
    }
}
